<template lang="pug">
  el-card.staffWrapper(shadow="never" style="border: none" v-loading="loading")
    el-row(type="flex" align="middle" justify="space-between")
      h2
        .c_red {{info.name}}
        span.ml5 教保师档案
      .extra.tr
        el-button(size="large" round @click="modalObj.visible = true") 考勤
        el-button.gradientVertical(size="large" round @click="editVisible = true") 编辑
    .contentBox
      basic-form(v-model="info" :disabled="true")
        <!--img(src="@/assets/22222.png")-->
        section.panel
          h3 学习履历
          ul.studyList.list
            li(v-for="item in (info.careers || [])" :key="item.id")
              | {{item.beginDate | dateFilter('YYYY年MM月DD')}} ~ {{item.endDate | dateFilter('YYYY年MM月DD')}}, {{item.description}}
        section.panel
          h3
            | 工作履历『在托育园的时刻』
            .score
              el-rate(v-if="workList.length > 0" :value="info.workScore" disabled show-score score-template="{value}" text-color="#DA473A" :colors="['#DA473A', '#DA473A', '#DA473A']")
          ul.workList.list
            li(v-for="item in (workList || [])" :key="item.id")
              span.title
                | {{item.content}}
                small.score {{item.rankVal}}分
        <!--section.panel-->
          <!--h3-->
            <!--| 课程学习-->
            <!--.score-->
              <!--el-rate(:value="4.6" disabled show-score score-template="{value}" text-color="#DA473A" :colors="['#DA473A', '#DA473A', '#DA473A']")-->
          <!--.learnList-->
            <!--.learn-item(v-for="(item, index) in (courseList || [])" :key="item.id")-->
              <!--el-row(:gutter="20" type="flex" align="middle" justify="space-between")-->
                <!--el-col(:span="10")-->
                  <!--.title-->
                    <!--span.sort {{index + 1}}-->
                    <!--.detail-->
                      <!--h4 {{item.title}}-->
                      <!--p.c_99.f13 课程类型：{{item.typeStr}}-->
                <!--el-col.c_99.f13(:span="7") 学习人数：{{randomNum(1, 99)}}-->
                <!--el-col.c_99.f13(:span="7") 学习时长：{{randomNum(10, 999)}}分钟-->
        section.panel
          h3
            | 家长评价
            .score
              el-rate(v-if="parentEvaList.length > 0" :value="info.parentEvaScore" disabled show-score score-template="{value}" text-color="#DA473A" :colors="['#DA473A', '#DA473A', '#DA473A']")
          .parentEva
            .evaItem(v-for="item in parentEvaList" :key="item.id")
              span.avatarBox
                el-avatar(:src="item.sourceHeadImgUrl" :size="52")
              .more
                .source
                  .name {{item.sourceName}}
                  el-rate(:value="item.rankVal" disabled show-score score-template="{value}分" text-color="#DA473A" :colors="['#DA473A', '#DA473A', '#DA473A']")
                .tagList()
                  el-tag(v-for="(tag, index) in item.tags.split('|')" :key="index") {{tag}}
                .content {{item.content}}
                .imgBox(v-if="item.resURLs && item.resURLs.length > 0")
                  a-image(
                    v-for="img in item.resURLs.split('|')"
                    :key="img"
                    :src="img"
                    width="120"
                    height="120"
                  )
                .time {{item.created | dateFilter}}
    add-drawer(:visible.sync="editVisible" :id="id" :detail="info"  @getList="getInfo")
    detail(:visible.sync="modalObj.visible" :id="id" :name="info.realName")
</template>
<script>
import { mapGetters } from 'vuex'
import AImage from '@/components/Basic/Image'
import Detail from './detailDrawer'
import EditTable from '@/components/Basic/EditTable'
import { courseStudyColumn } from './config'
import AddDrawer from '../components/add'
import { getListByStaffId, getDetailById, getScoreList } from '../api'
import BasicForm from '../components/add/basicForm'

export default {
  components: {
    AImage,
    BasicForm,
    EditTable,
    AddDrawer,
    Detail
  },
  data () {
    return {
      courseStudyColumn,
      info: {},
      workList: [],
      courseList: [
        {
          title: '托育机构的教研管理',
          typeStr: '托育日常',
          learnNum: 2,
          duration: 10
        },
        {
          title: '教育培训幼儿早教',
          typeStr: '早教',
          learnNum: 2,
          duration: 10
        },
        {
          title: '心理行为测评培训',
          typeStr: '测评',
          learnNum: 2,
          duration: 10
        }
      ],
      parentEvaList: [],
      editVisible: false,

      modalObj: {
        visible: false,
        id: ''
      }
    }
  },
  computed: {
    ...mapGetters(['curArea']),
    id () {
      return this.$route.query.id
    },
    operateType () {
      return this.$route.query.operateType
    }
  },
  created () {
    this.getInfo()
  },
  methods: {
    // 获取详情
    async getInfo () {
      this.loading = true
      const baseInfo = await getDetailById({ staffId: this.id })
      const moreInfo = await getListByStaffId({ staffId: this.id })
      const workList = await getScoreList({ staffId: this.id, sourceType: 0 })
      this.workList = workList?.content || []
      let workScore = 0.0
      if (this.workList.length > 0) {
        workScore = this.workList.reduce((sum, cur) => {
          return sum + cur.rankVal
        }, 0) / this.workList.length
      }

      const parentEvaList = await getScoreList({ staffId: this.id, sourceType: 1 })
      this.parentEvaList = parentEvaList?.content || []
      let parentEvaScore = 0.0
      if (this.parentEvaList.length > 0) {
        parentEvaScore = this.parentEvaList.reduce((sum, cur) => {
          return sum + cur.rankVal
        }, 0) / this.parentEvaList.length
      }

      this.info = {
        ...baseInfo,
        ...(moreInfo.content[0] || {}),
        workScore: workScore.toFixed(1),
        parentEvaScore: parentEvaScore.toFixed(1),
        headImgUrl: baseInfo.headImgUrl ? [{ url: baseInfo.headImgUrl }] : [],
        relations: (moreInfo.content[0]?.relations || []).map(x => {
          x.emergency = x.emergency ? '1' : '0'
          return x
        }),
        careers: (moreInfo.content[0]?.careers || []).map(x => {
          x.date = [new Date(x.beginDate), new Date(x.endDate)]
          return x
        })
      }
      console.log(this.info)
      this.loading = false
    },

    randomNum (Min, Max) {
      const Range = Max - Min
      const Rand = Math.random()
      return (Min + Math.round(Rand * Range))
    }
  }
}
</script>
<style lang="scss" scoped>

.contentBox{
  .panel {
    > h3 {
      font-size: 17px;
      font-family: PingFang SC;
      font-weight: bold;
      color: #333333;
      margin-bottom: 20px;
      position: relative;

      .score{
        position: absolute;
        right: 0;
        top: 0
      }
    }

    > .list{
      font-size: 15px;
      font-family: PingFang SC;
      ;
      color: #F5AC3C;
      line-height: 24px;
      padding: 0;
      margin: 0;

      li {
        padding-left: 30px;
        position: relative;
        list-style: none;
        color: #333333;

        + li {
          margin-top: 20px
        }

        &::before{
          content: '';
          display: block;
          position: absolute;
          width: 10px;
          height: 10px;
          background: #F5AC3C;
          left: 10px;
          top: 50%;
          margin-top: -5px
        }
      }

      &.studyList {
        li {
          &::before{
            border-radius: 50%;
          }
        }
      }

      &.workList {
        li {
          &::before{
            transform: rotate(45deg);
          }

          > span.title{
            position: relative;

            .score{
              color: #fff;
              position: absolute;
              left: 100%;
              bottom: 0;
              font-size: 15px;
              content: '';
              display: block;
              width: 36px;
              height: 40px;
              text-align: center;
              margin-left: 10px;
              background: url('~@/assets/fire2.png') center center no-repeat;
              background-size: 100% 100%;
              line-height: 54px;
            }
          }

        }
      }
    }

    .learnList{
      padding-left: 20px;
      margin-bottom: 24px;
      border-bottom: 1px dashed #E8E8E8;
      margin-top: 24px;

      .learn-item{
        margin-top: 30px;
      }

      .title{
        position: relative;
        padding-left: 55px;

        .sort{
          left: 10px;
          top: 0;
          color: #fff;
          text-align: center;
          content: '';
          display: block;
          position: absolute;
          width: 35px;
          height: 35px;
          line-height: 35px;
          background: url('~@/assets/sortBg.png') center center no-repeat;
          background-size: 100% 100%;
        }

        h4 {
          font-size: 15px;
          font-family: PingFang SC;
          font-weight: bold;
          color: #333333;
          line-height: 1;
          margin-top: 0;
          margin-bottom: 10px
        }
      }
    }

    + .panel{
      margin-top: 48px
    }
  }
}
  .parentEva{
    border-top: 1px dashed #E8E8E8;
    padding-top: 10px;
    .evaItem{
      margin-bottom: 30px;
      display: flex;
      flex-direction: row;
      width: 100%;
      .avatarBox {
        vertical-align: middle;
        border: 2px solid #fff;
        width: 56px;
        height: 56px;
        border-radius: 28px;
        display: inline-block;
        margin-right: 10px;
        box-shadow: 1px 2px 4px 4px rgba(0, 0, 0 ,0.08);
      }
      .more{
        display: flex;
        flex-direction: column;
        width: 100%;
        .source{
          display: flex;
          flex-direction: row;
          height: 56px;
          align-items: center;

          .name{
            flex: 1;
            font-size: 17px;
            font-family: PingFang SC;
            font-weight: bold;
            color: #333333;
            line-height: 24px;
          }
        }
        .tagList{
          margin-bottom: 10px;
          .el-tag{
            margin-right: 10px;
          }
        }
        .content{
          margin-top: 10px;
          font-size: 15px;
          font-family: PingFang SC;
          font-weight: 400;
          color: #333333;
          line-height: 24px;
        }
        .imgBox{
          margin-top: 10px;
        }
        .time{
          margin-top: 10px;
          font-size: 13px;
          font-family: PingFang SC;
          font-weight: 400;
          color: #999999;
          line-height: 24px;
        }
      }

    }
  }
</style>
